from flask import Blueprint, jsonify
from extensions import db
from .tasks import add2
from .models import Message

bp_th = Blueprint('bp_th', __name__)


@bp_th.route('/')
def index():
    res = add2.delay("hello word")
    return jsonify(res.wait())


@bp_th.get('/msgs')
def msg_list():
    messages = Message.query.all()
    results = []
    for message in messages:
        results.append(message.to_json())
    return jsonify(results)